﻿@{
    Layout = "_ZjcLayout";
    ViewData["Title"] = "政教处";
}

<div class="layui-container">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend>处理学生奖惩</legend>
    </fieldset>
    <div class="grid-demo grid-demo-bg1">
        学生奖励申请表
        <div class="demoTable">
            搜索ID：
            <div class="layui-inline">
                <input class="layui-input" name="id" id="awardid" autocomplete="off">
            </div>
            <button class="layui-btn" data-type="reload">搜索</button>
        </div>
        <table class="layui-hide" id="awardTable" lay-filter="awarduse"></table>
    </div>
    学生惩罚申请表
    <div class="demoTable">
        搜索ID：
        <div class="layui-inline">
            <input class="layui-input" name="id" id="punishid" autocomplete="off">
        </div>
        <button class="layui-btn" data-type="reload">搜索</button>
    </div>
    <table class="layui-hide" id="punishTable" lay-filter="punishuse"></table>
</div>

@section Scripts{
    <script src="~/layui-v2.5.5/layui/layui.all.js" charset="utf-8"></script>
    <script>
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#awardTable'
                , url: '/Api/AwardList'
                , cols: [[
                    { field: 'id', width: "6%", title: '编号', sort: true, fixed: true ,event: 'awardset', style: 'cursor: pointer;'}
                    , { field: 'sid', width: "12%", title: '学号' }
                    , { field: 'studentName', width: "12%", title: '姓名' }
                    , { field: 'studentClass', width: "12%", title: '班级' }
                    , { field: 'content', width: "18%", title: '奖励详情' }
                    , { field: 'awardContent', width: "15%", title: '具体措施' }
                    , { field: 'applyTime', width: "15%", title: '申请时间', sort: true }
                    , { field: 'state', width: "10%", title: '审核状态' }
                ]]
                , page: true
            });
            var $ = layui.$, active = {
                reload: function () {
                    var demoReload = $('#awardid');
                    //表单赋值
                    $.ajax({
                        url: '/Api/ShowAwardList',
                        data: { id: demoReload.val() },
                        type: "GET",
                        dataType: "JSON",
                        success: function (data) {
                            switch (data.code) {
                                case 0:
                                    awardData = data;
                                    table.render({
                                        elem: '#awardTable'
                                        , cols: [[
                                            { field: 'id', width: "6%", title: '编号', sort: true, fixed: true ,event: 'awardset', style: 'cursor: pointer;' }
                                            , { field: 'sid', width: "12%", title: '学号' }
                                            , { field: 'studentName', width: "12%", title: '姓名' }
                                            , { field: 'studentClass', width: "12%", title: '班级' }
                                            , { field: 'content', width: "18%", title: '奖励详情' }
                                            , { field: 'awardContent', width: "15%", title: '具体措施' }
                                            , { field: 'applyTime', width: "15%", title: '申请时间', sort: true }
                                            , { field: 'state', width: "10%", title: '审核状态' }
                                        ]]
                                        , page: true
                                        , data: awardData.award
                                    });
                                    break;
                                case 270:
                                    layer.alert("数据不存在哦！请重新试试", { icon: 2 });
                                    break;
                                default:
                                    layer.alert("数据异常，你再试试呗", { icon: 3 });
                            }
                        }
                    })
                }
            };
            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            //监听奖励表单元格事件
            table.on('tool(awarduse)', function (obj) {
                var data = obj.data;
                if (obj.event === 'awardset') {
                    layer.open({
                        type: 2,
                        area: ['600px', '820px'],
                        title: '奖励消息处理',
                        content: ['/ZJC/HandleAward?id=' + data.id, 'no'],
                        end: function () {
                            window.location.reload();
			            }
                    });
                }
            });
        });
    </script>
    <script>
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#punishTable'
                , url: '/Api/PunishList'
                , cols: [[
                    { field: 'id', width: "6%", title: '编号', sort: true, fixed: true, event: 'setSign', style: 'cursor: pointer;' }
                    , { field: 'sid', width: "12%", title: '学号' }
                    , { field: 'studentName', width: "12%", title: '姓名' }
                    , { field: 'studentClass', width: "12%", title: '班级' }
                    , { field: 'content', width: "18%", title: '惩罚详情' }
                    , { field: 'punishContent', width: "15%", title: '具体措施' }
                    , { field: 'applyTime', width: "15%", title: '申请时间', sort: true }
                    , { field: 'state', width: "10%", title: '审核状态' }
                ]]
                , page: true
            });
            var $ = layui.$, active = {
                reload: function () {
                    var demoReload = $('#punishid');
                    //表单赋值
                    $.ajax({
                        url: '/Api/ShowPunishList',
                        data: { id: demoReload.val() },
                        type: "GET",
                        dataType: "JSON",
                        success: function (data) {
                            switch (data.code) {
                                case 0:
                                    punishData = data;
                                    table.render({
                                        elem: '#punishTable'
                                        , cols: [[
                                            { field: 'id', width: "6%", title: '编号', sort: true, fixed: true ,event: 'setSign', style: 'cursor: pointer;' }
                                            , { field: 'sid', width: "12%", title: '学号' }
                                            , { field: 'studentName', width: "12%", title: '姓名' }
                                            , { field: 'studentClass', width: "12%", title: '班级' }
                                            , { field: 'content', width: "18%", title: '惩罚详情' }
                                            , { field: 'punishContent', width: "15%", title: '具体措施' }
                                            , { field: 'applyTime', width: "15%", title: '申请时间', sort: true }
                                            , { field: 'state', width: "10%", title: '审核状态' }
                                        ]]
                                        , page: true
                                        , data: punishData.award
                                    });
                                    break;
                                case 270:
                                    layer.alert("数据不存在哦！请重新试试", { icon: 2 });
                                    break;
                                default:
                                    layer.alert("数据异常，你再试试呗", { icon: 3 });
                            }
                        }
                    })
                }
            };
            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            //监听惩罚表单元格事件
            table.on('tool(punishuse)', function (obj) {
                var data = obj.data;
                if (obj.event === 'setSign') {
                    layer.open({
                        type: 2,
                        area: ['600px', '820px'],
                        title: '惩罚消息处理',
                        content: ['/ZJC/HandlePunish?id=' + data.id, 'no'],
                        end: function () {
                            window.location.reload();
			            }
                    });
                }
            });
        });
    </script>
}
